|
|
|
|
|
|
|
Figure 15.4
A convex solid (left) and a nonconvex solid (right). |
|
|
|
|
|
|
|
|
The solid on the right is not convex. It has three backfaces. Because they are backfaces, they are completely hidden by the body of the solid, so you definitely should not draw them. This solid also has three surfaces that are completely visible. It has one surface, however, that is not a backface and is still not completely visible. It is this sort of surface that makes backface removal insufficient for drawing nonconvex solids. |
|
|
|
|
|
|
|
|
You can still perform backface removal for nonconvex objects. All the backfaces are completely hidden, so you do not need to draw them. However, just because a surface is not a backface does not mean it is completely visible in a nonconvex solid. |
|
|
|
|
|
|
|
|
Backface Removal in Visual Basic |
|
|
|
|
|
|
|
|
The previous chapters treated most three-dimensional objects as collections of three-dimensional line segments. This approach lets you display objects, but it does not give you enough information about how the segments make up the surfaces to use backface removal. |
|
|
|
|
|
|
|
|
To provide the information you need, you can use Face3d and Solid3d classes. A Face3d object represents an outwardly oriented face on a solid. A Solid3d object contains a collection of Face3d objects that represent its faces. |
|
|
|
|
|
|
|
|
The data needs for the Face3d class are simple. The class contains an array that holds the points that make up the surface. For convenience, it also contains a Boolean flag IsCulled that is set to true if the surface is a backface. The object skips most other tasks if IsCulled is true. For example, the object does not bother to apply transformations to its points or draw itself if it has been culled. |
|
|
|
|
|
|
|
|
Most of the Face3d methods are straightforward. The AddPoints routine adds one or more new points to the polygon. The Apply routine applies a transformation to each of the points in the polygon. |
|
|
|
|
|
|
|
|
The ClipEye routine checks to see if any of the polygon's transformed points lie behind the center of projection. This prevents strange effects when the viewing direction points |
|
|
|
|
|